package cn.demo.cm.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.demo.common.annotation.Log;
import cn.demo.common.core.controller.BaseController;
import cn.demo.common.core.domain.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.demo.common.enums.BusinessType;
import cn.demo.cm.domain.CmFeedback;
import cn.demo.cm.service.ICmFeedbackService;
import cn.demo.common.utils.poi.ExcelUtil;
import cn.demo.common.core.page.PageR;
import cn.demo.common.core.page.PageQuery;
import com.mybatisflex.core.paginate.Page;


/**
 * 反馈信息Controller
 *
 * @author xtjun
 * @date 2024-06-04
 */
@Tag(name = "反馈信息")
@RestController
@RequestMapping("/cm/cmFeedback")
public class CmFeedbackController extends BaseController {
    @Resource
    private ICmFeedbackService cmFeedbackService;

    @Operation(summary = "查询反馈信息列表")
    @PreAuthorize("@ss.hasPermi('cm:cmFeedback:list')")
    @GetMapping("/list")
    public PageR<CmFeedback> list(CmFeedback cmFeedback, PageQuery pageQuery) {
        Page<CmFeedback> page = cmFeedbackService.selectCmFeedbackPage(cmFeedback, pageQuery);
        return PageR.ok(page);
    }

    @Operation(summary = "导出反馈信息列表")
    @PreAuthorize("@ss.hasPermi('cm:cmFeedback:export')")
    @Log(title = "反馈信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmFeedback cmFeedback) {
        List<CmFeedback> list = cmFeedbackService.selectCmFeedbackList(cmFeedback);
        ExcelUtil<CmFeedback> util = new ExcelUtil<CmFeedback>(CmFeedback.class);
        util.exportExcel(response, list, "反馈信息数据");
    }

    @Operation(summary = "获取反馈信息详细信息")
    @PreAuthorize("@ss.hasPermi('cm:cmFeedback:query')")
    @GetMapping(value = "/{id}")
    public R<CmFeedback> getInfo(@PathVariable("id") String id) {
        return R.ok(cmFeedbackService.selectCmFeedbackById(id));
    }

    @Operation(summary = "新增反馈信息")
    @PreAuthorize("@ss.hasPermi('cm:cmFeedback:add')")
    @Log(title = "反馈信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody CmFeedback cmFeedback) {
        return toAjax(cmFeedbackService.insertCmFeedback(cmFeedback));
    }

    @Operation(summary = "修改反馈信息")
    @PreAuthorize("@ss.hasPermi('cm:cmFeedback:edit')")
    @Log(title = "反馈信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody CmFeedback cmFeedback) {
        return toAjax(cmFeedbackService.updateCmFeedback(cmFeedback));
    }

    @Operation(summary = "删除反馈信息")
    @PreAuthorize("@ss.hasPermi('cm:cmFeedback:remove')")
    @Log(title = "反馈信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable List<String> ids) {
        return toAjax(cmFeedbackService.deleteCmFeedbackByIds(ids));
    }
}
